
var colorArr = [
    { "color": "#5470C6" },
    { "color": "#91CC75" },
    { "color": "#FAC858" },
    { "color": "#EE6666" },
    { "color": "#73C0DE" },
];
// 用户ID
let id = getUrlParam("id");
$(function () {
    GetUserRole();
});
//获取用户权限
function GetUserRole() {
    // let thisdata = [];
    // thisdata.push(InitRole(id));
    let USERdata = InitRole(id);
    if (USERdata != null) {
        init();

    }
    else OpenErrmsg("../../web/errhtml/404.html");
}
function init(){
    $('#db_Start').datebox('setValue', GetDateStr(-13));
    $('#db_End').datebox('setValue', getCurrDate());
    initTitle();
    BindNowDatalist();
    $('#tab_Chem').tabs({
        onSelect: function (title) {
            if (title == "累计用量") {
                SearchData();
            } else {
                initTitle();
                BindNowDatalist();
            }
        }
    });
}
function initTitle() {
    var data = [
        { "id": "B01", "name": "药剂1" },
        { "id": "B02", "name": "药剂2" },
        { "id": "B03", "name": "药剂3" },
        { "id": "B04", "name": "药剂4" },
        { "id": "B05", "name": "药剂5" },
        { "id": "B06", "name": "药剂6" }
    ];
    $('#tg_Type1').tagbox({
        // url:'combobox_data.json',
        data: data,
        valueField: 'id',
        textField: 'name',
        onChange: function (newValue, oldValue) {
            if (newValue.length > 5) {
                $('#tg_Type1').tagbox('setValues', oldValue);
            } else {
                $('#tg_Type1').tagbox('setValues', newValue);
            }
            InitChart1();
        },
        onLoadSuccess: function (data) {
            var arrchoose = [];
            if (arrchoose.length > 0)
                arrchoose.push(data[0]);
            if (arrchoose.length > 1)
                arrchoose.push(data[1])
            $('#tg_Type1').tagbox('setValues', arrchoose);
            InitChart1();
        },
    });
}
//加载当前用量图表
function InitChart1() {
    let xAxis = ["11:00", "11:15", "11:30", "11:45", "12:00"];
    let data = [
        { "code": "01", "name": "药剂1", "data": ["34", "617", "53", "54", "32"] },
        { "code": "02", "name": "药剂2", "data": ["345", "167", "253", "564", "232"] },
        { "code": "03", "name": "药剂3", "data": ["124", "671", "573", "504", "132"] },
        { "code": "04", "name": "药剂4", "data": ["234", "567", "534", "594", "320"] }
    ];

    var myChart = echarts.init(document.getElementById('chartdiv1'));
    var xAxisDataLine = new Array();
    var seriesDataLine = new Array();
    for (var i = 0; i < data.length; i++) {
        var item = data[i];
        xAxisDataLine.push(item.name)
        seriesDataLine.push({
            name: item.name,
            type: "line",
            // stack: 'Total',
            data: item.data
        });
    }
    console.log(xAxisDataLine)
    // 指定图表的配置项和数据
    var option = {
        title: {
            text: '',
            textStyle: {
                fontSize: 12, //字体大小
            },
        },
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: xAxisDataLine,

        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        toolbox: {
            // feature: {
            //     saveAsImage: {}
            // }
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: xAxis
        },
        yAxis: {
            type: 'value'
        },
        series: seriesDataLine
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
}
//加载当前药剂列表信息
function BindNowDatalist() {
    let data = [
        { "code": "01", "chemtype": "药剂1", "currentuse": "10", "caninventory": "20", "emptycannum": "20", "fullcannum": "30", "totalinventory": "40", "planuseday": "50", },
        { "code": "01", "chemtype": "药剂2", "currentuse": "10", "caninventory": "20", "emptycannum": "20", "fullcannum": "30", "totalinventory": "40", "planuseday": "50", },
        { "code": "01", "chemtype": "药剂3", "currentuse": "10", "caninventory": "20", "emptycannum": "20", "fullcannum": "30", "totalinventory": "40", "planuseday": "50", },
        { "code": "01", "chemtype": "药剂4", "currentuse": "10", "caninventory": "20", "emptycannum": "20", "fullcannum": "30", "totalinventory": "40", "planuseday": "50", },
        { "code": "01", "chemtype": "药剂5", "currentuse": "10", "caninventory": "20", "emptycannum": "20", "fullcannum": "30", "totalinventory": "40", "planuseday": "50", },
        { "code": "01", "chemtype": "药剂6", "currentuse": "10", "caninventory": "20", "emptycannum": "20", "fullcannum": "30", "totalinventory": "40", "planuseday": "50", }
    ];
    //加载数据
    $('#dg_DateList1').datagrid({
        data: data
    });
}

//累计用量
function SearchData() {
    InitTotalTitle();
    InitChart2();
    BindTotalDatalist();
}
//根据日期查询药剂类型下拉框
function InitTotalTitle() {
    var data = [
        { "id": "B01", "name": "药剂1" },
        { "id": "B02", "name": "药剂2" },
        { "id": "B03", "name": "药剂3" },
        { "id": "B04", "name": "药剂4" },
        { "id": "B05", "name": "药剂5" },
        { "id": "B06", "name": "药剂6" }
    ];
    $('#tg_Type2').tagbox({
        // url:'combobox_data.json',
        data: data,
        valueField: 'id',
        textField: 'name',
        onChange: function (newValue, oldValue) {
            if (newValue.length > 5) {
                $('#tg_Type2').tagbox('setValues', oldValue);
            } else {
                $('#tg_Type2').tagbox('setValues', newValue);
            }
            InitChart2();
        },
        onLoadSuccess: function (data) {
            var arrchoose = [];
            if (arrchoose.length > 0)
                arrchoose.push(data[0]);
            if (arrchoose.length > 1)
                arrchoose.push(data[1])
            $('#tg_Type2').tagbox('setValues', arrchoose);
            InitChart2();
        },
    });
}
//加载累计用量图表
function InitChart2() {

    let xAxis = ["11/1", "11/2", "11/3", "11/4", "11/5"];
    let data = [
        { "code": "01", "name": "药剂1", "data": ["34", "617", "53", "54", "32"] },
        { "code": "02", "name": "药剂2", "data": ["345", "167", "253", "564", "232"] },
        { "code": "03", "name": "药剂3", "data": ["124", "671", "573", "504", "132"] },
        { "code": "04", "name": "药剂4", "data": ["234", "567", "534", "594", "320"] }
    ];

    var myChart = echarts.init(document.getElementById('chartdiv2'));
    var xAxisDataLine = new Array();
    var seriesDataLine = new Array();
    for (var i = 0; i < data.length; i++) {
        var item = data[i];
        xAxisDataLine.push(item.name)
        seriesDataLine.push({
            name: item.name,
            type: "line",
            // stack: 'Total',
            data: item.data
        });
    }
    console.log(xAxisDataLine)
    // 指定图表的配置项和数据
    var option = {
        title: {
            text: '药剂费用情况',
            textStyle: {
                fontSize: 12, //字体大小
            },
        },
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: xAxisDataLine,

        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        toolbox: {
            // feature: {
            //     saveAsImage: {}
            // }
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: xAxis
        },
        yAxis: {
            type: 'value'
        },
        series: seriesDataLine
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
}
//加载当前药剂列表信息
function BindTotalDatalist() {
    let StartDate = $('#db_Start').datebox('getValue');
    let EndDate = $('#db_End').datebox('getValue');
    let daycount = DateDiff(StartDate, EndDate);
    if (StartDate != "" && EndDate != "" && daycount > 14) {
        $.messager.alert('警告', '查询日期不能超过两周！');
    } else {
        let columns = [];
        //后台返回列头
        let dataTitle = [
            { "ID": "B00", "name": "日期" },
            { "ID": "B01", "name": "药剂1" },
            { "ID": "B02", "name": "药剂2" },
            { "ID": "B03", "name": "药剂3" },
            { "ID": "B04", "name": "药剂4" },
            { "ID": "B05", "name": "药剂5" },
            { "ID": "B06", "name": "药剂6" },
            { "ID": "B07", "name": "药剂7" }
        ];
        for (let index = 0; index < dataTitle.length; index++) {
            const element = dataTitle[index];
            columns.push({ field: element.ID, title: element.name, width: 100 });
        }
        //后台返回数据
        var data = [
            { "B00": "2021-09-08", "B01": "10", "B02": "2021", "B03": "9", "B04": "09", "B05": "77", "B06": "66", "B07": "33" },
            { "B00": "2021-09-08", "B01": "10", "B02": "2021", "B03": "9", "B04": "09", "B05": "77", "B06": "66", "B07": "33" },
            { "B00": "2021-09-08", "B01": "10", "B02": "2021", "B03": "9", "B04": "09", "B05": "77", "B06": "66", "B07": "33" },
            { "B00": "2021-09-08", "B01": "10", "B02": "2021", "B03": "9", "B04": "09", "B05": "77", "B06": "66", "B07": "33" },
            { "B00": "2021-09-08", "B01": "10", "B02": "2021", "B03": "9", "B04": "09", "B05": "77", "B06": "66", "B07": "33" },
            { "B00": "2021-09-08", "B01": "10", "B02": "2021", "B03": "9", "B04": "09", "B05": "77", "B06": "66", "B07": "33" },
            { "B00": "2021-09-08", "B01": "10", "B02": "2021", "B03": "9", "B04": "09", "B05": "77", "B06": "66", "B07": "33" },
            { "B00": "2021-09-08", "B01": "10", "B02": "2021", "B03": "9", "B04": "09", "B05": "77", "B06": "66", "B07": "33" },
            { "B00": "2021-09-08", "B01": "10", "B02": "2021", "B03": "9", "B04": "09", "B05": "77", "B06": "66", "B07": "33" },
            { "B00": "2021-09-08", "B01": "10", "B02": "2021", "B03": "9", "B04": "09", "B05": "77", "B06": "66", "B07": "33" },
            { "B00": "2021-09-08", "B01": "10", "B02": "2021", "B03": "9", "B04": "09", "B05": "77", "B06": "66", "B07": "33" },
            { "B00": "2021-09-08", "B01": "10", "B02": "2021", "B03": "9", "B04": "09", "B05": "77", "B06": "66", "B07": "33" },
            { "B00": "2021-09-08", "B01": "10", "B02": "2021", "B03": "9", "B04": "09", "B05": "77", "B06": "66", "B07": "33" },
            { "B00": "2021-09-08", "B01": "10", "B02": "2021", "B03": "9", "B04": "09", "B05": "77", "B06": "66", "B07": "33" },
        ];
        //加载数据
        $('#dg_DateList2').datagrid({
            data: data,
            columns: [columns]
        });
    }
}
